package com.xiaoma.seckill.controller;

import com.xiaoma.seckill.entity.SeckillRedis;
import com.xiaoma.seckill.service.SeckillService;
import entity.Goods;
import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.JwtUtils;
import utils.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: xiaoma
 * @Date: 2021/7/27 17:13
 * @description:
 */
@RestController
@RequestMapping("seckill")
public class SeckillController {
    @Autowired
    private SeckillService seckillService;

    @RequestMapping("/hello")
    public R hello(){
        return R.ok().put("data","hello");
    }
    @GetMapping("/getCurrentSeckill")
    public R getCurrentSeckill(){
        List<SeckillRedis> currentSeckill = seckillService.getCurrentSeckill();
        return  R.ok().put("data",currentSeckill);
    }
    @GetMapping("/getCurrentSeckill/{id}")
    public R getGoodsByGoodsId(@PathVariable("id") Integer id){
        SeckillRedis seckillRedis= seckillService.getGoodsByGoodsId(id);
        return  R.ok().put("data",seckillRedis);
    }
    @GetMapping("/kill")
    public R kill(@RequestParam("killId") String killId,
                  @RequestParam("key") String key,
                  @RequestParam("num") Integer num, HttpServletRequest request){
//        String uid = JwtUtils.getMemberIdByJwtToken(request);
        String uid= "3";
        String orderSn = seckillService.kill(killId, key, num, Integer.parseInt(uid));
        return R.ok().put("data",orderSn);
    }
}
